﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Web.UI;
using System.ComponentModel;
using TA.DotNetUtils;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Popup control which is shown when a specified scenario is used in a post.
	/// </summary>
	public class TurboProgress : BasePopupControl
	{
		#region PROPERTIES
		/// <summary>
		/// Props.
		/// </summary>
		protected static new Properties _clientProperties = Define(BasePopupControl._clientProperties, new[] {
			new PropertyDefinition<int>("DisplayTimeout", "DT", 0),
		});
		/// <summary>
		/// Props.
		/// </summary>
		public override Properties ClientProperties
		{
			get
			{
				return _clientProperties;
			}
		}
		#endregion
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public TurboProgress()
		{
			InclusionMode = InclusionMode.AllExceptExcluded;
			_mpvScenarios = new MultiControlValue<PostScenario>(this);
		}
		#endregion
		#region PROPS
		/// <summary>
		/// Number of milliseconds to wait before displaying the progress control.
		/// </summary>
		public int DisplayTimeout
		{
			get
			{
				return GetProperty<int>("DisplayTimeout");
			}
			set
			{
				ViewState["DisplayTimeout"] = value;
			}
		}
		/// <summary>
		/// Inclusion mode for scenarios.
		/// </summary>
		public InclusionMode InclusionMode { get; set; }
		/// <summary>
		/// Comma-separated list of scenario IDs, relative to this control.
		/// </summary>
		public string ScenarioIds { get { return _mpvScenarios.Value; } set { _mpvScenarios.Value = value; } }
		/// <summary>
		/// List of scenario IDs, relative to this control.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Browsable(false)]
		public List<string> ScenarioIdList { get { return _mpvScenarios.ValueList; } }
		/// <summary>
		/// List of scenarios.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Browsable(false)]
		public List<PostScenario> ScenarioList { get { return this._mpvScenarios.ControlList; } }
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		MultiControlValue<PostScenario> _mpvScenarios;
		#endregion
		#region METHODS
		#region INIT
		/// <summary>
		/// Initialization.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			if (this.TPage != null)
				this.TPage.ProgressControls.Add(this);
		}
		/// <summary>
		/// Registers TurboProgress.js.
		/// </summary>
		protected internal override void RegisterIncludes(IncludeCollection includes)
		{
			base.RegisterIncludes(includes);

			includes.Add(new ScriptResourceInclude("TA.Turbo.Res.JS.Popup.TurboProgress.js", typeof(TurboProgress)));
		}
		#endregion
		#region RENDER
		/// <summary>
		/// Renders this control only if client script is not confirmed to be unavailable.
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderControl(HtmlTextWriter writer)
		{
			if (this.TPage == null || this.TPage.JavaScript != false)
				base.RenderControl(writer);
		}
		#endregion
		#endregion
		#endregion
	}
}
